<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page import="java.util.*"%>
<%@ page import="admin.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<!-- 상단프레임 -->
<%@ include file="/Dmyna/admin/head.jsp" %>

	<!-- 게시물 수 -->
	<%!static int PAGE_SIZE = 10;%>

	<!--  -->
	<%
		String pageNum = request.getParameter("page");
			if (pageNum == null) pageNum = "1";
			int currentPage = Integer.parseInt(pageNum);
			AdminOrderManager manager = AdminOrderManager.getInstance();
			int count = manager.count();
			int totalPageCount = 0;
			int startRow = 0, endRow = 0;
			if (count > 0) {
		totalPageCount = count / PAGE_SIZE;
		if (count % PAGE_SIZE > 0) totalPageCount++;
		startRow = (currentPage - 1) * PAGE_SIZE + 1;
		endRow = currentPage * PAGE_SIZE;
			}
			List<AdminOrderItem> list = manager.selectList(startRow, endRow);
	%>

	<!--  -->
	<c:set var="list" value="<%=list%>" />

	<!-- 상단제목 -->
<table width="900" align=center cellpadding=0 cellspacing=0>
	<tr>
		<td>
			<div
				style="border:1px solid #ddd; height:34px; background:url(${WEB_ROOT }/img/bbs/title_bg.gif) repeat-x;">
				<div
					style="font-weight: bold; font-size: 14px; margin: 7px 0 0 10px;"
					align="center">::&nbsp;&nbsp;주문 내역&nbsp;&nbsp;::</div>
			</div>
		</td>
	</tr>
</table>
<p>

<script type="text/javascript">
function orderStepUpdate(form){
	alert(from.oi_no.value);
	alert(from.oi_step.value);
	return false;
}
</script>

<c:set var="WEB_ROOT" value="/Dmyna" />
<table width="900" align="center" cellpadding="0" cellspacing="0">
	<tr>
		<td>
			<table width="900" cellpadding="0" cellspacing="0" class="board_list">
				<col width="25%" />
				<col width="25%" />
				<col width="25%" />
				<col width="25%" />
				<tr><td colspan="4"></td></tr>
				<tr align="center">
					<td>주문 날짜</td>
					<td>주문 번호</td>
					<td>주문 금액</td>
					<td>주문 상태</td>
				</tr>

				<c:if test="${empty list }">
					<tr>
						<td bgcolor="#f0f0f0" colspan="4" height="100" align="center">게시물이 없습니다.</td>
					</tr>
				</c:if>

				<c:if test="${!empty list }">
					<c:forEach var="order" items="${list }">
						<c:set var="bgChk" value="${ (cnt % 2) == 0 ? 0 : 1 }" />
						<tr class="bg${bgChk }">
							<td class="num">${order.oi_date }</td>
							<td class="name"><a href="javascript:goView(${order.oi_no })">${order.oi_no }</a></td>
							<td class="num"><fmt:formatNumber value="${order.oi_total_price }" type="number"/></td>

							<td align="center">

<form name="orderStep"  action="/order.do"  method="post">
<input type="hidden" name="oi_no" value="${order.oi_no }">
							<select name="oi_step">
							<option value="1" ${order.oi_step ==1 ?  "selected": "" }>상품준비중</option>
							<option value="2" ${order.oi_step ==2 ?  "selected": "" }>배송중</option>
							<option value="3" ${order.oi_step ==3 ?  "selected": "" }>배송완료</option>
							<option value="4" ${order.oi_step ==4 ?  "selected": "" }>환불요청</option>
							<option value="5" ${order.oi_step ==5 ?  "selected": "" }>환불완료</option>
							</select>
							<input type="submit" value="상태변경" />
</form>
							</td>
						</tr>
					</c:forEach>
				</c:if>
				<tr>
					<td colspan='4' height=25 align=center>
						<div class="board_page">

							<!--페이지 번호 시작-->
							<c:set var="count" value="<%=Integer.toString(count)%>" />
							<c:set var="PAGE_SIZE" value="<%=Integer.toString(PAGE_SIZE)%>" />
							<c:set var="currentPage" value="<%=Integer.toString(currentPage)%>" />
							<c:if test="${count > 0 }">

								<c:set var="pageCount"
									value="${count / PAGE_SIZE + (count % PAGE_SIZE == 0 ? 0 : 1) }" />
								<c:set var="startPage"
									value="${currentPage - (currentPage % 10 == 0 ? 10:(currentPage % 10)) + 1 }" />
								<c:set var="endPage" value="${startPage + 9 }" />
								<c:if test="${endPage > pageCount }">
									<c:set var="endPage" value="${pageCount }" />
								</c:if>

								<!-- 처음버튼 -->
								<c:if test="${startPage > 1  }">
									<a href="javascript:goPage(${startPage})"> <img
										src='${WEB_ROOT }/img/bbs/page_begin.gif' border='0'
										align='absmiddle' title='처음'>&nbsp;
									</a>
								</c:if>

								<!-- 이전버튼 -->
								<c:if test="${startPage > 10  }">
									<a href="javascript:goPage(${startPage-10 })"> <img
										src='${WEB_ROOT }/img/bbs/page_prev.gif' border='0'
										align='absmiddle' title='이전'>&nbsp;
									</a>
								</c:if>

								<!-- 숫자표시 -->
								<c:if test="${startPage > 1  }">
								<c:forEach var="pageNo" begin="${startPage }" end="${endPage }">
									<c:if test="${currentPage == pageNo }">
										<font size="4">
									</c:if>
									<a href="javascript:goPage(${pageNo })">${pageNo }&nbsp;</a>
									<c:if test="${currentPage == pageNo }">
										</font>
									</c:if>
								</c:forEach>
								</c:if>

								<!-- 다음버튼 -->
								<c:if test="${endPage < pageCount  }">
									<a href="javascript:goPage(${startPage+10 })"> <img
										src='${WEB_ROOT }/img/bbs/page_next.gif' border='0'
										align='absmiddle' title='다음'>&nbsp;
									</a>
								</c:if>

								<!-- 맨끝버튼 -->
								<c:if test="${startPage > 1  }">
									<a
										href="javascript:goPage(<fmt:formatNumber value="${endPage}" pattern="#"/>)">
										<img src='${WEB_ROOT }/img/bbs/page_end.gif' border='0'
										align='absmiddle' title='맨끝'>
									</a>
								</c:if>
							</c:if>
							<!--페이지 번호 종료-->

						</div>
					</td>
				</tr>
				<tr>
					<!-- 전체게시물수 표시 -->
					<td colspan="4" height=25 align="left"><%=count%> 개의 주문내역이
						있습니다.</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<!-- 하단프레임 -->
<%@ include file="/Dmyna/admin/tail.jsp"%>

<!--  -->
<script language="JavaScript">
	function goPage(pageNo) {
		document.move.action = "${WEB_ROOT }/admin/order/orderList.jsp";
		document.move.page.value = pageNo;
		document.move.submit();
	}

	function goView(id) {
		document.move.action = "${WEB_ROOT }/admin/order/orderView.jsp";
		document.move.id.value = id;
		document.move.submit();
	}
	
	function chk_id(f) {
		id = f.mb_id.value;
		if (f.mb_id.value == "") {
			alert("아이디를 입력하세요.");
			f.mb_id.focus();
			return;
		}
		w = window.open("idCheck.jsp?id=" + id, "", "width=250,height=150");
	}
</script>

<!--  -->
<form name="move" method="post">
	<input type="hidden" name="id" value="" /> 
	<input type="hidden" name="page" value="" />
</form>